package com.mt.component.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类名称：CacheFilter <br>
 * 类描述： 设置flex页面不缓存<br>
 * 创建人： 马腾 <br>
 * 创建时间：Dec 7, 2012 11:12:36 PM <br>
 * 修改人： 马腾 <br>
 * 修改时间：Dec 7, 2012 11:12:36 PM <br>
 */
public class CacheFilter implements Filter {
	
	private boolean debugMode = false;

	@Override
	public void destroy() {}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		if (debugMode && req.getRequestURI() != null && req.getRequestURI().endsWith(".swf")){ 
			HttpServletResponse arg = (HttpServletResponse) response;
			arg.setHeader("pragma", "no-cache");
			arg.setHeader("cache-control", "no-cache");
			arg.setHeader("expires", "0");
		}
		
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		debugMode = true;
	}
}
